package bb.lanxing.lib.devices.utils;

import android.annotation.SuppressLint;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.util.Log;
import bb.lanxing.lib.devices.core.ble.SpecificationAttributes;
import kotlin.Metadata;
import kotlin.jvm.internal.Intrinsics;
/* compiled from: GattExt.kt */
@Metadata(d1 = {"\u0000\"\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000b\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\u001a\u000e\u0010\u0002\u001a\u00020\u00012\u0006\u0010\u0003\u001a\u00020\u0004\u001a\u0014\u0010\u0005\u001a\u00020\u0006*\u00020\u00072\u0006\u0010\b\u001a\u00020\tH\u0007\u001a\u0014\u0010\n\u001a\u00020\u0006*\u00020\u00072\u0006\u0010\b\u001a\u00020\tH\u0007\u001a\u0014\u0010\u000b\u001a\u00020\u0006*\u00020\u00072\u0006\u0010\b\u001a\u00020\tH\u0007\u001a\u0014\u0010\f\u001a\u00020\u0006*\u00020\u00072\u0006\u0010\b\u001a\u00020\tH\u0007\"\u000e\u0010\u0000\u001a\u00020\u0001X\u0086T¢\u0006\u0002\n\u0000¨\u0006\r"}, d2 = {"TAG", "", "getWriteType", "type", "", "enableIndications", "", "Landroid/bluetooth/BluetoothGatt;", "characteristic", "Landroid/bluetooth/BluetoothGattCharacteristic;", "enableNotification", "read", "write", "lib-devices-xz_release"}, k = 2, mv = {1, 7, 1}, xi = 48)

public final class GattExtKt {
    public static final String TAG = "GattExt";

    @SuppressLint("MissingPermission")
    public static final boolean enableNotification(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic characteristic) {
        Intrinsics.checkNotNullParameter(bluetoothGatt, "<this>");
        Intrinsics.checkNotNullParameter(characteristic, "characteristic");
        if ((characteristic.getProperties() & 16) == 0) {
            return false;
        }
        Log.d(TAG, "gatt.setCharacteristicNotification(" + characteristic.getUuid() + ", true)");
        bluetoothGatt.setCharacteristicNotification(characteristic, true);
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(SpecificationAttributes.CLIENT_CHARACTERISTIC_CONFIG2);
        if (descriptor == null) {
            return false;
        }
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
        Log.d(TAG, "Enabling notifications for " + characteristic.getUuid());
        Log.d(TAG, "gatt.writeDescriptor(" + SpecificationAttributes.CLIENT_CHARACTERISTIC_CONFIG2 + ", value=0x01-00)");
        return bluetoothGatt.writeDescriptor(descriptor);
    }

    @SuppressLint("MissingPermission")
    public static final boolean enableIndications(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic characteristic) {
        Intrinsics.checkNotNullParameter(bluetoothGatt, "<this>");
        Intrinsics.checkNotNullParameter(characteristic, "characteristic");
        if ((characteristic.getProperties() & 32) == 0) {
            return false;
        }
        Log.d(TAG, "gatt.setCharacteristicNotification(" + characteristic.getUuid() + ", true)");
        bluetoothGatt.setCharacteristicNotification(characteristic, true);
        BluetoothGattDescriptor descriptor = characteristic.getDescriptor(SpecificationAttributes.CLIENT_CHARACTERISTIC_CONFIG2);
        if (descriptor == null) {
            return false;
        }
        descriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);
        Log.d(TAG, "Enabling indications for " + characteristic.getUuid());
        Log.d(TAG, "gatt.writeDescriptor(" + SpecificationAttributes.CLIENT_CHARACTERISTIC_CONFIG2 + ", value=0x02-00)");
        return bluetoothGatt.writeDescriptor(descriptor);
    }

    @SuppressLint("MissingPermission")
    public static final boolean read(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic characteristic) {
        Intrinsics.checkNotNullParameter(bluetoothGatt, "<this>");
        Intrinsics.checkNotNullParameter(characteristic, "characteristic");
        if ((characteristic.getProperties() & 2) == 0) {
            return false;
        }
        Log.d(TAG, "Reading characteristic " + characteristic.getUuid());
        Log.d(TAG, "gatt.readCharacteristic(" + characteristic.getUuid() + ')');
        return bluetoothGatt.readCharacteristic(characteristic);
    }

    public static final boolean write(BluetoothGatt bluetoothGatt, BluetoothGattCharacteristic characteristic) {
        Intrinsics.checkNotNullParameter(bluetoothGatt, "<this>");
        Intrinsics.checkNotNullParameter(characteristic, "characteristic");
        if ((characteristic.getProperties() & 12) == 0) {
            return false;
        }
        Log.d(TAG, "Writing characteristic " + characteristic.getUuid() + " (" + getWriteType(characteristic.getWriteType()) + ')');
        @SuppressLint("MissingPermission") boolean writeCharacteristic = bluetoothGatt.writeCharacteristic(characteristic);
        Log.d(TAG, "gatt.writeCharacteristic(" + characteristic.getUuid() + ") result: " + writeCharacteristic);
        return writeCharacteristic;
    }

    public static final String getWriteType(int i) {
        if (i != 1) {
            if (i == 2) {
                return "WRITE REQUEST";
            }
            if (i == 4) {
                return "WRITE SIGNED";
            }
            return "UNKNOWN: " + i;
        }
        return "WRITE COMMAND";
    }
}
